<template>
  <view class="app">
    <view class="contentArea">
      <u-loading-page loading-color="#000000" loadingMode="spinner" :loading="!treeDataFlag"></u-loading-page>
      <treeComponent :treeDataS="treeData" v-if="treeDataFlag"></treeComponent>
    </view>
  </view>
</template>

<script>
/**
 * 引入组件
 */
import treeComponent from "@/safetyProductionResponsibilitySystem/components/tree/index.vue"

/**
 * 引入API接口请求数据
 * getDepartmentNewListApi: 获取部门列表接口
 */
import {getDepartmentNewListApi} from "@/apis/work/common.js"
import { getUserInfo } from '@/utils/auth.js'

export default {
  /**
   * 组件名称安全组织管理
   */
  name: "safetyProductionResponsibilitySystem",

  /**
   * 注册组件
   */
  components: {
    treeComponent
  },
  
  /**
   * 定义数据
   */
  data() {
    return {
      /* treeDataS数据 */
      treeData: null,
      treeDataFlag: false,
    }
  },

  /**
   * 计算属性
   */
  computed: {},

  /**
   * 定义方法
   */
  methods: {
    /* 获取部门列表数据 */
    async getDepartmentNewListApi () {
      let userInfo = getUserInfo()
      
      if(userInfo && userInfo.company && userInfo.company.id) {
        this.treeDataFlag = false
        let req = await getDepartmentNewListApi({ id: userInfo.company.id });
        req[0].nodeIsFlag = true;
        this.treeData = req
        this.treeDataFlag = true
      } else {
        uni.showToast({ title: '当前登录用户没有机构信息', icon: 'none' })
      }
    }
  },

  /**
   * 数据监听
   */
  watch: {},

  /**
   * Vue创建生命周期钩子
   */
  created () {
    this.getDepartmentNewListApi()
  }
}
 
</script>

<style lang="scss" scoped>
  .app {
    min-height: 98vh;
  }
  .contentArea {
    background-color: #FFF;
    padding: 20rpx 10rpx 100rpx 10rpx;
  }
</style>
